#ifndef _ASYNCUDPSOCKIMPL_H_
#define _ASYNCUDPSOCKIMPL_H_

#include "stdafx.h"

class CUdpSocketImpl :	public	IUdpSocket,
					public	CUnknownImp,
					public  	IoDgramBase
{
public:
	CUdpSocketImpl(void);
	virtual ~CUdpSocketImpl(void);
	
	BEGIN_STDCOM_MAP
		STDCOM_INTERFACE_ENTRY(IUdpSocket)
		STDCOM_INTERFACE_ENTRY_UNKNOWN_(IUdpSocket)
	END_STDCOM_MAP


	//IIoDevice
	std_method(CloseIo)(UINT rw);
	std_method(BindIo)();
	std_method(OpenIo)();

	//ISocket
	std_method(CreateSock)();
	std_method(CloseSock)();
	std_method(IsOpen)();
	std_method(AttachSock)(_sock_t sock);
	std_method_(_sock_t, DetachSock)();
	std_method(SetOption)(LPCSTR opt, int val);
	std_method(GetOption)(LPCSTR opt, int* val);

	//IUdpSocket
	std_method_(BUFFER_SIZE, SyncSend)(NET_ADDR addr, NET_PORT port,
		BUFFER_PTR buf, BUFFER_SIZE size);
	std_method_(BUFFER_SIZE, SyncRecv)(NET_ADDR addr, NET_PORT port,
		BUFFER_PTR buf, BUFFER_SIZE size);
	std_method(ReadIo)(NET_ADDR addr, NET_PORT port,
		IBase* pBase, event_id event);
	std_method(WriteIo)(NET_ADDR addr, NET_PORT port,
		IBase* pBase, event_id event);

private:
	typedef map<string, int>			SocketOptionTable;
	typedef SocketOptionTable::iterator	SocketOption;

	_sock_t				m_sock;
	ULONG				m_ulConTmSec;
	SocketOptionTable	m_MapSockOption;
private:
	void				DgramWritecb(void *data, BUFFER_SIZE len);
	void				DgramReadcb(void *data, BUFFER_SIZE len);
	void				DgramEventcb(void *data, event_id what);

public:
	IoDgramBase*		GetIoUdp();
	CharArrayPtr		m_pAddr;
	NET_PORT			m_uPort;
};

#endif
